package com.kuke.pdf;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class PdfTranferTest {

	public static void main(String[] args) {
		try {
			pdf2ImageFilePath();
			//pdf2ImageInputStream();
			//pdf2ImageByte();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static void pdf2ImageFilePath() throws Exception {
		PdfTranfer pdfTranfer = new PdfTranfer();
		List<byte[]> ins = pdfTranfer.pdf2Image("D:\\tmp\\11.pdf", "png", 1.5f);
		for (int i = 0; i < ins.size(); i++) {
			byte[] data = ins.get(i);
			FileUtils.writeByteArrayToFile(new File("D:\\tmp\\f_"+i+".png"), data);
		}
	}
	public static void pdf2ImageInputStream() throws Exception {
		PdfTranfer pdfTranfer = new PdfTranfer();
		InputStream in = new FileInputStream(new File("C:\\tmp\\image0008.pdf"));
		List<byte[]> ins = pdfTranfer.pdf2Image(in, "png", 2f);
		for (int i = 0; i < ins.size(); i++) {
			byte[] data = ins.get(i);
			FileUtils.writeByteArrayToFile(new File("C:\\tmp\\input_"+i+".png"), data);
		}
	}
	public static void pdf2ImageByte() throws Exception {
		PdfTranfer pdfTranfer = new PdfTranfer();
		File file = new File("C:\\tmp\\image0008.pdf");
		byte[] bytes = FileUtils.readFileToByteArray(file);
		List<byte[]> ins = pdfTranfer.pdf2Image(bytes, "png", 2f);
		for (int i = 0; i < ins.size(); i++) {
			byte[] data = ins.get(i);
			FileUtils.writeByteArrayToFile(new File("C:\\tmp\\byte_"+i+".png"), data);
		}
	}
}
